package controller

import (
	"gitee.com/Frank098/devops-app-mgt/model"
	"gitee.com/Frank098/devops-app-mgt/service"
	"github.com/gin-gonic/gin"
)

var Pv pv

type pv struct{}

// @Tags Pv
// @Summary 获取pv详情
// @Accept json
// @Produce json
// @Param pv_name query string true "pv名称"
// @Success 200 {object} model.Result ""
// @Failure 400 {object} model.Result""
// @Router /pv/info [GET]
func (p *pv) GetPvInfo(ctx *gin.Context) {
	var params model.GetPv
	if err := ctx.Bind(&params); err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	data, err := service.Pv.GetPvInfo(params.PvName)
	if err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	SuccessResponse(ctx, &model.Result{
		Code: 200,
		Msg:  "Success",
		Data: data,
	})
}

// @Tags Pv
// @Summary 删除pv
// @Accept json
// @Produce json
// @Param "" body model.GetPv true "删除pv"
// @Success 200 {object} model.Result ""
// @Failure 400 {object} model.Result""
// @Router /pv/delete [DELETE]
func (p *pv) DeletePv(ctx *gin.Context) {
	var params model.GetPv
	if err := ctx.ShouldBindJSON(&params); err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	if err := service.Pv.DeletePv(params.PvName); err != nil {
		ErrorResponse(ctx, err, 400)
		return
	}
	SuccessResponse(ctx, &model.Result{
		Code: 200,
		Msg:  "Success",
		Data: "删除Pv成功",
	})
}
